//
//  StatusPictureView.swift
//  swift_learning
//
//  Created by aron on 2017/2/2.
//  Copyright © 2017年 arons. All rights reserved.
//

import UIKit

class StatusPictureView: UICollectionView {
    
    fileprivate var picUrls : [URL] = [URL]()
    
    override func awakeFromNib() {
        self.delegate = self
        self.dataSource = self
        
        // 注册Cell
        self.register(UINib(nibName: "StatusPicCell", bundle: nil), forCellWithReuseIdentifier: NSStringFromClass(StatusPicCell.self))
    }
    
    func setPicUrls(picUrls: [URL]) {
        self.picUrls = picUrls
        
        // 刷新
        self.reloadData()
    }
}


// MARK: - UICollectionViewDataSource, UICollectionViewDelegate
extension StatusPictureView : UICollectionViewDataSource, UICollectionViewDelegate {
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return picUrls.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell : StatusPicCell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(StatusPicCell.self), for: indexPath) as! StatusPicCell
        // 设置数据
        cell.statucPicImgView.sd_setImage(with: picUrls[indexPath.row], placeholderImage: DEFAULT_PLACEHOLDER_IMAGE())
        return cell
    }
}
